

class Camera
  
  attr_reader :tracked_object
  attr_accessor :offset
  
  def initialize
    @offset = vect(0,0)
  end
  
  def up(amount)
    @offset.y += amount
  end
  
  def down(amount)
    @offset.y -= amount
  end
  
  def left(amount)
    @offset.x += amount
  end
  
  def right(amount)
    @offset.x -= amount
  end
  
  def adjusted_coords(x,y)
    adjusted_vect(vect(x,y))
  end
  
  # world coords to screen coords
  def adjusted_vect(vect)
    if @tracked_object then
      p = @tracked_object.body.p
    
      vect -= p   
    end
    
    vect.x += SCREEN_WIDTH / 2
    vect.y += SCREEN_HEIGHT / 2
    
    vect += @offset
    
    return vect
  end
  
  # screen coords to world coords
  def inverse_adjusted_vect(vect)
    if @tracked_object then
      p = @tracked_object.body.p
    
      vect += p   
    end
    
    vect.x -= SCREEN_WIDTH / 2
    vect.y -= SCREEN_HEIGHT / 2
    
    vect -= @offset
    
    return vect
  end
  
  def follows_object(obj)
    if obj == nil then 
      @tracked_object = nil 
      return
    end
    
    if !(obj.is_a? MovableObject) then
      puts obj, " is not a movable object!"
      return nil
    end
    @tracked_object = obj
  end
  
end
